#!/bin/bash
TOP_DIR=$(cd $(dirname "$0") && pwd)
IP_HOSTNAME_FILE=hostname.txt
IP_LIST=$2
# LOG_COL_PATH=$3
# BEAT_LOG_TOPIC=$4

cd $TOP_DIR

filebeat(){
    echo "Start Init Qcloud"

    COL_NUM=`echo $IP_LIST | awk -F ',' '{print NF}'`
    echo "[INFO] Deploy Host Number: $COL_NUM"
    echo "[INFO] IP LIST:            $IP_LIST"

    echo "[filebeat]" >inventory/filebeat
    for((i=1;i<=$COL_NUM;i++));do
        HOST_IP=`echo $IP_LIST | awk -F ','  -v col_num="$i" '{ print $col_num }'`
        echo "$HOST_IP" >> inventory/filebeat
    done
    ansible-playbook role_filebeat_other.yml
    # ansible-playbook role_filebeat.yml --extra-vars "{'beat_log_topic':'$BEAT_LOG_TOPIC', 'log_col_path': '$LOG_COL_PATH'}"
}

case $1 in
    "filebeat")
    filebeat
    ;;
    *)
    echo "---------------------------------------------------------------------------------------"
    echo "Enter filebeat:                install filebeat"
    echo "---------------------------------------------------------------------------------------"
    ;;
esac
